﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

namespace Sample.Collection
{
    class CollectionSample
    {
        public static void Execute()
        {
            NotifyCollection<string> collection = new NotifyCollection<string>();
            collection.Add("First");
            collection.Insert(0, "Zero");
            collection[1] = "Third";


            collection.Contains("Second");

            collection.Remove("First");
            collection.Clear();
        }
    }

    class NotifyCollection<T> : Collection<T>
    {
        public new void Add(T item)
        {
            Console.WriteLine("Add");
            base.Add(item);
        }

        public new void Clear()
        {
            Console.WriteLine("Clear");
            base.Clear();
        }

        public new bool Contains(T item)
        {
            Console.WriteLine("Contains");
            return base.Contains(item);
        }

        public new int IndexOf(T item)
        {
            Console.WriteLine("Index of");
            return base.IndexOf(item);
        }

        public new void Insert(int index, T item)
        {
            Console.WriteLine("Insert at " + index);
            base.Insert(index, item);
        }

        public new bool Remove(T item)
        {
            Console.WriteLine("Remove");
            return base.Remove(item);
        }

        public new void RemoveAt(int index)
        {
            Console.WriteLine("Remove at" + index);
            base.RemoveAt(index);
        }

        protected override void ClearItems()
        {
            Console.WriteLine("Clear items");
            base.ClearItems();
        }

        protected override void InsertItem(int index, T item)
        {
            Console.WriteLine("Insert item at " + index);
            base.InsertItem(index, item);
        }

        protected override void RemoveItem(int index)
        {
            Console.WriteLine("Remove item at " + index);
            base.RemoveItem(index);
        }

        protected override void SetItem(int index, T item)
        {
            Console.WriteLine("Set item at " + index);
            base.SetItem(index, item);
        }
    }
}
